﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ValidationFramework.Reflection;
using ValidationFramework.Tests.TestHelpers;

namespace ValidationFramework.Tests
{
	[TestFixture]
	public class ValidationFacadeTest
	{
		#region TestModel
		private class Car
		{
			public int NumberOfDoors { get; set; }
            public int NumberOfSeats { get; set; }
		}
		#endregion
		[Test]
		public void Should_Be_Able_To_Add_Rules_Fluently()
		{
			// Arrange
			Validation.Initialize();
			var originalPolicy = Validation.GetValidationPolicy<Car>(property => property.NumberOfDoors);
			Assert.AreEqual(0, originalPolicy.RuleCount);

			// Act
			Validation.ConfigurePolicyFor<Car>(x =>
			{
				x.Ensure(property => property.NumberOfDoors)
					.Passes(new AlwaysFailValidator());

				x.Ensure(property => property.NumberOfDoors)
					.Passes(new AlwaysFailValidator()); ;
			});
			

			// Assert
			var policy = Validation.GetValidationPolicy<Car>(property => property.NumberOfDoors);
			Assert.AreEqual(2, policy.RuleCount);
		}
	}
}
